package pl.symulatorbiegu;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

/**
 * Created by Lukas on 09.12.13.
 */
public class HeatSimulator {
    protected ArrayList<Double> initialValues;
    protected ArrayList<Double> simulatedValues = new ArrayList<Double>();
    protected Map<Double, Integer> resultsMap = new HashMap<Double, Integer>();
    protected Map<Double, Integer> sortedMap;
    protected Map<Integer,Integer> pointsMap = new HashMap<Integer, Integer>();
    protected Double simulationRange = new Double(1.0);

    public HeatSimulator(ArrayList<Double> values) {
        initialValues = values;
    }


    public void simulateHeat() {
        for (Double initialValue : initialValues) {
            simulatedValues.add(initialValue + Math.random() * simulationRange);
        }
        getHeatResults();
    }

    protected void getHeatResults() {
        setResultsMap();
        assignPoints();
    }

    protected void setResultsMap() {
        for (int i = 0; i < initialValues.size(); ++i) {
            resultsMap.put(simulatedValues.get(i), i);
        }
        sortedMap = new TreeMap<Double, Integer>(resultsMap);
    }

    protected void assignPoints() {
        Integer i = 0;
        for (Map.Entry<Double, Integer> entry : sortedMap.entrySet()) {
            pointsMap.put(entry.getValue(),i++);
        }
    }

    public void setSimulationRange(Double simulationRange) {
        this.simulationRange = simulationRange;
    }

    public Map<Integer, Integer> getPointsMap() {
        return pointsMap;
    }

}
